﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Manager_AddAssess : System.Web.UI.Page
{
    CommonClass ccobj = new CommonClass();
    DBClass dbobj = new DBClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            bindDepart();
    }
    protected void bindDepart()
    {
        string strsql = "select * from Department";
        DataTable dstable = dbobj.GetDataSet(strsql, "tabdepartment");
        DropDownList1.DataSource = dstable.DefaultView;
        DropDownList1.DataTextField = dstable.Columns[1].ToString();
        DropDownList1.DataValueField = dstable.Columns[0].ToString();
        DropDownList1.DataBind();

        DropDownList1.Items.Insert(0, "请选择");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strsql = "select * from Assess where AssessID='" + TextBox1.Text.Trim() + "'";
        DataTable dstable = dbobj.GetDataSet(strsql, "tabassess");
        if (dstable.Rows.Count > 0)
            Response.Write(ccobj.MessageBox("该用户已注册！"));
        else
        {
            string strinsert = "insert into Assess (AssessID,PassWord,AssessName,DepartmentID,IsManager,Email) values('" + TextBox1.Text.Trim() + "','" + TextBox1.Text.Trim() + "','" + TextBox2.Text.Trim() + "','" + DropDownList1.SelectedValue.ToString() + "'," + (CheckBox1.Checked ? 1 : 0) + ",'" + TextBox3.Text.Trim() + "')";
            dbobj.ExecNonQuery(strinsert);
            Response.Write(ccobj.MessageBox("记录添加成功！"));

            if (CheckBox1.Checked)
            {
                string strsql1 = "select * from Admin where AdminID='" + TextBox1.Text.Trim() + "'";
                DataTable dt = dbobj.GetDataSet(strsql1, "tabadmin");
                if (dt.Rows.Count > 0)
                    Response.Write(ccobj.MessageBox("管理员表中已经有该用户"));
                else
                {
                    string strsql2 = "insert into Admin (AdminID,AdminName,PassWord,DepartmentID,IsAssessMan) values('" + TextBox1.Text.Trim() + "','" + TextBox2.Text.Trim() + "','" + TextBox1.Text.Trim() + "','" + DropDownList1.SelectedValue.ToString() + "'," + 0 + ")";
                    dbobj.ExecNonQuery(strsql2);
                    Response.Write(ccobj.MessageBox("该管理员已添加到管理员表中！"));
                }
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        DropDownList1.SelectedIndex = 0;
        CheckBox1.Checked = false;
    }
}